﻿$(function () {





    // Generate datepicker panel
    $(".datepicker").datepicker();

    /* Button click functions */


    /* Button : Eng Dept Support Misc Support */
    $("#btnEngDeptSupportMisc").click(function (evt) {
        // Enter reason
        var reason = GetReason("Please enter the reason you are logging onto Eng Dept Support/Misc (50 chrs max)", "Please enter reason", 50);

        // Clock On to activity
        if (reason != null && reason != "") {
            ClockOn(2, $("#btnEngDeptSupportMisc").text(), reason);
        }
    });

    /* Button : Production Support */
    $("#btnProductionSupport").click(function (evt) {
        ClockOn(3, $("#btnProductionSupport").text(), "");
    });

    /* Button : Technical Support */
    $("#btnTechnicalSupport").click(function (evt) {
        ClockOn(4, $("#btnTechnicalSupport").text(), "");
    });
    /* ---------------------------- */

    /* Button : Sales Support */
    $("#btnSalesSupport").click(function (evt) {
        ClockOn(5, $("#btnSalesSupport").text(), "");
    });
    /* ---------------------------- */

    /* Button : Purchasing Support */
    $("#btnPurchasingSupport").click(function (evt) {
        ClockOn(9, $("#btnPurchasingSupport").text(), "");
    });
    /* ---------------------------- */

    /* Button : Computer */
    $("#btnComputer").click(function (evt) {
        ClockOn(6, $("#btnComputer").text(), "");
    });
    /* ---------------------------- */

    /* Button : Training */
    $("#btnTraining").click(function (evt) {
        ClockOn(7, $("#btnTraining").text(), "");
    });
    /* ---------------------------- */

    /* Button : General Meeting */
    $("#btnGeneralMeeting").click(function (evt) {
        ClockOn(8, $("#btnGeneralMeeting").text(), "");
    });
    /* ---------------------------- */

    /* Button : R & D */
    $("#btnRD").click(function (evt) {
        // Enter reason
        var reason = GetReason("Please enter the reason you are logging onto R & D (50 chrs max)", "Please enter reason", 50);

        // Clock On to activity
        if (reason != null && reason != "") {
            ClockOn(2, $("#btnEngDeptSupportMisc").text(), reason);
        }
    });
    /* ---------------------------- */

    /* Button : General Meeting */
    $("#btnEndOfDay").click(function (evt) {
        ClockOff();
    });
    /* ---------------------------- */

    /* Dropdownlist : Project */
    $("select#ddlProject").change(function (evt) {
        GetProjectData();
    });
    /* ---------------------------- */

    $("select#ddlEngineers").change(function (evt) {
        if ($("select#ddlEngineers").val() != "-1" && $("select#ddlEngineers").val() != "" && $("select#ddlEngineers").val() != null) {
            // Get user id
            var userId = $("select#ddlEngineers").val();
            // Get project that belong to user
            GetProjectListByUserId(userId);
        }
        else {
            // Clear all grid's data
            ClearGridData();
        }
    });


    $("#btnResumePreviousTask").click(function (evt) {

        // Clear all grid's data
        ClearGridData();

        // resume previous task
        ResumePreviousTask();

        // disable the button
        $("#btnResumePreviousTask").attr("disabled", "disabled");

    });

    $('#chkOpenProjects').click(function () {
        if ($(this).attr("checked") == "checked") {
            // Do stuff
            $("#chkClosedProjects").removeAttr('checked');
            LoadProjects("LoadOpenProjects", "");
        }
        else { LoadProjects("", ""); }
    });


    $('#chkClosedProjects').click(function () {
        if ($(this).attr("checked") == "checked") {
            // Do stuff
            $("#chkOpenProjects").removeAttr('checked');
            LoadProjects("", "LoadClosedProjects");
        }
        else { LoadProjects("", ""); }
    });

    $("#btnFreeEntryAdmin").click(function () {
        FreeEntryAdmin();
    });

    // Disabled all input
    $("input").attr("disabled", "disabled");

    // Remove disabled
    $("#chkClosedProjects").removeAttr("disabled");
    $("#chkOpenProjects").removeAttr("disabled");
    $(".requesttoken input").removeAttr("disabled");


    //disable free entry button
    $("#btnFreeEntry").bind('click', function (e) {
        e.preventDefault();
    });
    $("#btnFreeEntry").attr("disabled", "disabled");
    $("#btnFreeEntryAdmin").bind('click', function (e) {
        e.preventDefault();
    });
    $("#btnFreeEntryAdmin").attr("disabled", "disabled");

    // disable Resume Previous Task Button
    $("#btnResumePreviousTask").attr("disabled", "disabled");


});